home *** CD-ROM | disk | FTP | other *** search
/ QuickTime 2.0 Developer Kit / QuickTime 2.0 Developer Kit.iso / mac / MAC / System Extensions / Sound Manager 3.0 / Sound.p < prev   
Text File  |  1993-07-19  |  15KB  |  490 lines

  1. {************************************************************
  2.  
  3.  Sound Manager 3.0 release
  4.  
  5.  Created: Tuesday, June 29, 1993 3:28:55 PM
  6.  Sound.p
  7.  Pascal Interface to the Macintosh Libraries
  8.  
  9.   Copyright Apple Computer, Inc. 1986-1993
  10.   All rights reserved
  11.  
  12. ************************************************************}
  13.  
  14.  
  15. {$IFC UNDEFINED UsingIncludes}
  16. {$SETC UsingIncludes := 0}
  17. {$ENDC}
  18.  
  19. {$IFC NOT UsingIncludes}
  20.     UNIT Sound;
  21.     INTERFACE
  22. {$ENDC}
  23.  
  24. {$IFC UNDEFINED UsingSound}
  25. {$SETC UsingSound := 1}
  26.  
  27. {$I+}
  28. {$SETC SoundIncludes := UsingIncludes}
  29. {$SETC UsingIncludes := 1}
  30. {$IFC UNDEFINED UsingTypes}
  31. {$I $$Shell(PInterfaces)Types.p}
  32. {$ENDC}
  33. {$SETC UsingIncludes := SoundIncludes}
  34.  
  35. CONST
  36. swMode = -1;                                    {Sound Driver modes}
  37. ftMode = 1;
  38. ffMode = 0;
  39.  
  40. soundListRsrc = 'snd ';                         {Resource types used by Sound Manager}
  41. kSoundHardwareType = 'sdev';                    {component type for sound devices}
  42.  
  43. twelfthRootTwo = 1.05946309434;
  44. rate44khz = $AC440000;                            {44100.00000 in fixed-point}
  45. rate22khz = $56EE8BA3;                            {22254.54545 in fixed-point}
  46. rate11khz = $2B7745D1;                            {11127.27273 in fixed-point}
  47.  
  48. {synthesizer numbers for SndNewChannel}
  49. squareWaveSynth = 1;                            {square wave synthesizer}
  50. waveTableSynth = 3;                             {wave table synthesizer}
  51. sampledSynth = 5;                                {sampled sound synthesizer}
  52.  
  53. {old Sound Manager MACE synthesizer numbers}
  54. MACE3snthID = 11;
  55. MACE6snthID = 13;
  56.  
  57. kMiddleC = 60;                                    {MIDI note value for middle C}
  58. kSimpleBeepID = 1;                                {reserved resource ID for Simple Beep}
  59. kFullVolume = $0100;                            {1.0, setting for full hardware output volume}
  60.  
  61. {command numbers for SndDoCommand and SndDoImmediate}
  62. nullCmd = 0;
  63. initCmd = 1;
  64. freeCmd = 2;
  65. quietCmd = 3;
  66. flushCmd = 4;
  67. reInitCmd = 5;
  68.  
  69. waitCmd = 10;
  70. pauseCmd = 11;
  71. resumeCmd = 12;
  72. callBackCmd = 13;
  73. syncCmd = 14;
  74.  
  75. availableCmd = 24;
  76. versionCmd = 25;
  77. totalLoadCmd = 26;
  78. loadCmd = 27;
  79.  
  80. freqDurationCmd = 40;
  81. restCmd = 41;
  82. freqCmd = 42;
  83. ampCmd = 43;
  84. timbreCmd = 44;
  85. getAmpCmd = 45;
  86. volumeCmd = 46;                                    {sound manager 3.0 or later only}
  87. getVolumeCmd = 47;                                {sound manager 3.0 or later only}
  88.  
  89. waveTableCmd = 60;
  90. phaseCmd = 61;
  91.  
  92. soundCmd = 80;
  93. bufferCmd = 81;
  94. rateCmd = 82;
  95. continueCmd = 83;
  96. doubleBufferCmd = 84;
  97. getRateCmd = 85;
  98.  
  99. sizeCmd = 90;
  100. convertCmd = 91;
  101.  
  102. stdQLength = 128;
  103. dataOffsetFlag = $8000;
  104.  
  105. {channel initialization parameters}
  106. waveInitChannelMask = $07;
  107. waveInitChannel0 = $04;                            {wave table only, Sound Manager 2.0 and earlier}
  108. waveInitChannel1 = $05;                            {wave table only, Sound Manager 2.0 and earlier}
  109. waveInitChannel2 = $06;                            {wave table only, Sound Manager 2.0 and earlier}
  110. waveInitChannel3 = $07;                            {wave table only, Sound Manager 2.0 and earlier}
  111.  
  112. initChan0 = waveInitChannel0;                    {obsolete spelling}
  113. initChan1 = waveInitChannel1;                    {obsolete spelling}
  114. initChan2 = waveInitChannel2;                    {obsolete spelling}
  115. initChan3 = waveInitChannel3;                    {obsolete spelling}
  116.  
  117. initPanMask = $0003;                            {mask for right/left pan values}
  118. initSRateMask = $0030;                            {mask for sample rate values}
  119. initStereoMask = $00C0;                         {mask for mono/stereo values}
  120. initCompMask = $FF00;                            {mask for compression IDs}
  121.  
  122. initChanLeft = $0002;                            {left stereo channel}
  123. initChanRight = $0003;                            {right stereo channel}
  124. initNoInterp = $0004;                            {no linear interpolation}
  125. initNoDrop = $0008;                             {no drop-sample conversion}
  126. initMono = $0080;                                {monophonic channel}
  127. initStereo = $00C0;                             {stereo channel}
  128. initMACE3 = $0300;                                {MACE 3:1}
  129. initMACE6 = $0400;                                {MACE 6:1}
  130.  
  131. kUseOptionalOutputDevice = -1;                    {only for Sound Manager 3.0 or later}
  132.  
  133. stdSH = $00;                                    {Standard sound header encode value}
  134. extSH = $FF;                                    {Extended sound header encode value}
  135. cmpSH = $FE;                                    {Compressed sound header encode value}
  136.  
  137. notCompressed = 0;                                {compression ID's}
  138. fixedCompression = -1;                            {compression ID for fixed-sized compression}
  139. variableCompression = -2;                        {compression ID for variable-sized compression}
  140. twoToOne = 1;
  141. eightToThree = 2;
  142. threeToOne = 3;
  143. sixToOne = 4;
  144.  
  145. outsideCmpSH = 0;                                {MACE constants}
  146. insideCmpSH = 1;
  147. aceSuccess = 0;
  148. aceMemFull = 1;
  149. aceNilBlock = 2;
  150. aceBadComp = 3;
  151. aceBadEncode = 4;
  152. aceBadDest = 5;
  153. aceBadCmd = 6;
  154. sixToOnePacketSize = 8;
  155. threeToOnePacketSize = 16;
  156. stateBlockSize = 64;
  157. leftOverBlockSize = 32;
  158.  
  159. firstSoundFormat = $0001;                        {general sound format}
  160. secondSoundFormat = $0002;                        {special sampled sound format (HyperCard)}
  161.  
  162. dbBufferReady = $00000001;                        {double buffer is filled}
  163. dbLastBuffer = $00000004;                        {last double buffer to play}
  164.  
  165. sysBeepDisable = $0000;                         {SysBeep() enable flags}
  166. sysBeepEnable = $0001;
  167.  
  168. unitTypeNoSelection = $FFFF;                    {unitTypes for AudioSelection.unitType}
  169. unitTypeSeconds = $0000;
  170.  
  171. TYPE
  172. {            Structures for Sound Driver           }
  173.  
  174.  
  175. FreeWave = PACKED ARRAY [0..30000] OF Byte;
  176.  
  177. FFSynthPtr = ^FFSynthRec;
  178. FFSynthRec = RECORD
  179.     mode: INTEGER;
  180.     count: Fixed;
  181.     waveBytes: FreeWave;
  182.     END;
  183.  
  184. Tone = RECORD
  185.     count: INTEGER;
  186.     amplitude: INTEGER;
  187.     duration: INTEGER;
  188.     END;
  189.  
  190.  
  191. Tones = ARRAY [0..5000] OF Tone;
  192.  
  193. SWSynthPtr = ^SWSynthRec;
  194. SWSynthRec = RECORD
  195.     mode: INTEGER;
  196.     triplets: Tones;
  197.     END;
  198.  
  199.  
  200. Wave = PACKED ARRAY [0..255] OF Byte;
  201. WavePtr = ^Wave;
  202.  
  203. FTSndRecPtr = ^FTSoundRec;
  204. FTSoundRec = RECORD
  205.     duration: INTEGER;
  206.     sound1Rate: Fixed;
  207.     sound1Phase: LONGINT;
  208.     sound2Rate: Fixed;
  209.     sound2Phase: LONGINT;
  210.     sound3Rate: Fixed;
  211.     sound3Phase: LONGINT;
  212.     sound4Rate: Fixed;
  213.     sound4Phase: LONGINT;
  214.     sound1Wave: WavePtr;
  215.     sound2Wave: WavePtr;
  216.     sound3Wave: WavePtr;
  217.     sound4Wave: WavePtr;
  218.     END;
  219.  
  220. FTSynthPtr = ^FTSynthRec;
  221. FTSynthRec = RECORD
  222.     mode: INTEGER;
  223.     sndRec: FTSndRecPtr;
  224.     END;
  225.  
  226. {            Structures for Sound Manager           }
  227.  
  228. SndCommand = PACKED RECORD
  229.     cmd: INTEGER;
  230.     param1: INTEGER;
  231.     param2: LONGINT;
  232.     END;
  233.  
  234.  
  235.  
  236. SndChannelPtr = ^SndChannel;
  237. SndChannel = PACKED RECORD
  238.     nextChan: SndChannelPtr;
  239.     firstMod: Ptr;                                {reserved for the Sound Manager}
  240.     callBack: ProcPtr;
  241.     userInfo: LONGINT;
  242.     wait: LONGINT;                                {The following is for internal Sound Manager use only.}
  243.     cmdInProgress: SndCommand;
  244.     flags: INTEGER;
  245.     qLength: INTEGER;
  246.     qHead: INTEGER;
  247.     qTail: INTEGER;
  248.     queue: ARRAY [0..stdQLength - 1] OF SndCommand;
  249.     END;
  250.  
  251. {MACE structures}
  252. StateBlockPtr = ^StateBlock;
  253. StateBlock = RECORD
  254.     stateVar: ARRAY [0..stateBlockSize - 1] OF INTEGER;
  255.     END;
  256.  
  257. LeftOverBlockPtr = ^LeftOverBlock;
  258. LeftOverBlock = RECORD
  259.     count: LONGINT;
  260.     sampleArea: PACKED ARRAY [0..leftOverBlockSize - 1] OF Byte;
  261.     END;
  262.  
  263. ModRef = RECORD
  264.     modNumber: INTEGER;
  265.     modInit: LONGINT;
  266.     END;
  267.  
  268. SndListPtr = ^SndListResource;
  269. SndListHndl = ^SndListPtr;
  270. SndListResource = RECORD
  271.     format: INTEGER;
  272.     numModifiers: INTEGER;
  273.     modifierPart: ARRAY [0..0] OF ModRef;        {This is a variable length array}
  274.     numCommands: INTEGER;
  275.     commandPart: ARRAY [0..0] OF SndCommand;    {This is a variable length array}
  276.     dataPart: PACKED ARRAY [0..0] OF Byte;        {This is a variable length array}
  277.     END;
  278.  
  279. Snd2ListPtr = ^Snd2ListResource;
  280. Snd2ListHndl = ^Snd2ListPtr;
  281. Snd2ListResource = RECORD                        {HyperCard sound resource format}
  282.     format: INTEGER;
  283.     refCount: INTEGER;
  284.     numCommands: INTEGER;
  285.     commandPart: ARRAY [0..0] OF SndCommand;    {This is a variable length array}
  286.     dataPart: PACKED ARRAY [0..0] OF Byte;        {This is a variable length array}
  287.     END;
  288.  
  289. SoundHeaderPtr = ^SoundHeader;
  290. SoundHeader = PACKED RECORD
  291.     samplePtr: Ptr;                             {if NIL then samples are in sampleArea}
  292.     length: LONGINT;                            {length of sound in bytes}
  293.     sampleRate: Fixed;                            {sample rate for this sound}
  294.     loopStart: LONGINT;                         {start of looping portion}
  295.     loopEnd: LONGINT;                            {end of looping portion}
  296.     encode: Byte;                                {header encoding}
  297.     baseFrequency: Byte;                        {baseFrequency value}
  298.     sampleArea: PACKED ARRAY [0..0] OF Byte;
  299.     END;
  300.  
  301. CmpSoundHeaderPtr = ^CmpSoundHeader;
  302. CmpSoundHeader = PACKED RECORD
  303.     samplePtr: Ptr;                             {if nil then samples are in sample area}
  304.     numChannels: LONGINT;                        {number of channels i.e. mono = 1}
  305.     sampleRate: Fixed;                            {sample rate in Apples Fixed point representation}
  306.     loopStart: LONGINT;                         {loopStart of sound before compression}
  307.     loopEnd: LONGINT;                            {loopEnd of sound before compression}
  308.     encode: Byte;                                {data structure used , stdSH, extSH, or cmpSH}
  309.     baseFrequency: Byte;                        {same meaning as regular SoundHeader}
  310.     numFrames: LONGINT;                         {length in frames ( packetFrames or sampleFrames )}
  311.     AIFFSampleRate: Extended80;                   {IEEE sample rate}
  312.     markerChunk: Ptr;                            {sync track}
  313.     format: OSType;                             {data format type, was futureUse1}
  314.     futureUse2: LONGINT;                        {reserved by Apple}
  315.     stateVars: StateBlockPtr;                    {pointer to State Block}
  316.     leftOverSamples: LeftOverBlockPtr;            {used to save truncated samples between compression calls}
  317.     compressionID: INTEGER;                     {0 means no compression, non zero means compressionID}
  318.     packetSize: INTEGER;                        {number of bits in compressed sample packet}
  319.     snthID: INTEGER;                            {resource ID of Sound Manager snth that contains NRT C/E}
  320.     sampleSize: INTEGER;                        {number of bits in non-compressed sample}
  321.     sampleArea: PACKED ARRAY [0..0] OF Byte;    {space for when samples follow directly}
  322.     END;
  323.  
  324. ExtSoundHeaderPtr = ^ExtSoundHeader;
  325. ExtSoundHeader = PACKED RECORD
  326.     samplePtr: Ptr;                             {if nil then samples are in sample area}
  327.     numChannels: LONGINT;                        {number of channels,  ie mono = 1}
  328.     sampleRate: Fixed;                            {sample rate in Apples Fixed point representation}
  329.     loopStart: LONGINT;                         {same meaning as regular SoundHeader}
  330.     loopEnd: LONGINT;                            {same meaning as regular SoundHeader}
  331.     encode: Byte;                                {data structure used , stdSH, extSH, or cmpSH}
  332.     baseFrequency: Byte;                        {same meaning as regular SoundHeader}
  333.     numFrames: LONGINT;                         {length in total number of frames}
  334.     AIFFSampleRate: Extended80;                   {IEEE sample rate}
  335.     markerChunk: Ptr;                            {sync track}
  336.     instrumentChunks: Ptr;                        {AIFF instrument chunks}
  337.     AESRecording: Ptr;
  338.     sampleSize: INTEGER;                        {number of bits in sample}
  339.     futureUse1: INTEGER;                        {reserved by Apple}
  340.     futureUse2: LONGINT;                        {reserved by Apple}
  341.     futureUse3: LONGINT;                        {reserved by Apple}
  342.     futureUse4: LONGINT;                        {reserved by Apple}
  343.     sampleArea: PACKED ARRAY [0..0] OF Byte;    {space for when samples follow directly}
  344.     END;
  345.  
  346. ConversionBlockPtr = ^ConversionBlock;
  347. ConversionBlock = RECORD
  348.     destination: INTEGER;
  349.     unused: INTEGER;
  350.     inputPtr: CmpSoundHeaderPtr;
  351.     outputPtr: CmpSoundHeaderPtr;
  352.     END;
  353.  
  354. SMStatusPtr = ^SMStatus;
  355. SMStatus = PACKED RECORD
  356.     smMaxCPULoad: INTEGER;
  357.     smNumChannels: INTEGER;
  358.     smCurCPULoad: INTEGER;
  359.     END;
  360.  
  361. SCStatusPtr = ^SCStatus;
  362. SCStatus = RECORD
  363.     scStartTime: Fixed;
  364.     scEndTime: Fixed;
  365.     scCurrentTime: Fixed;
  366.     scChannelBusy: BOOLEAN;
  367.     scChannelDisposed: BOOLEAN;
  368.     scChannelPaused: BOOLEAN;
  369.     scUnused: BOOLEAN;
  370.     scChannelAttributes: LONGINT;
  371.     scCPULoad: LONGINT;
  372.     END;
  373.  
  374. AudioSelectionPtr = ^AudioSelection;
  375. AudioSelection = PACKED RECORD
  376.     unitType: LONGINT;
  377.     selStart: Fixed;
  378.     selEnd: Fixed;
  379.     END;
  380.  
  381. SndDoubleBufferPtr = ^SndDoubleBuffer;
  382. SndDoubleBuffer = PACKED RECORD
  383.     dbNumFrames: LONGINT;
  384.     dbFlags: LONGINT;
  385.     dbUserInfo: ARRAY [0..1] OF LONGINT;
  386.     dbSoundData: PACKED ARRAY [0..0] OF Byte;
  387.     END;
  388.  
  389. SndDoubleBufferHeaderPtr = ^SndDoubleBufferHeader;
  390. SndDoubleBufferHeader = PACKED RECORD
  391.     dbhNumChannels: INTEGER;
  392.     dbhSampleSize: INTEGER;
  393.     dbhCompressionID: INTEGER;
  394.     dbhPacketSize: INTEGER;
  395.     dbhSampleRate: Fixed;
  396.     dbhBufferPtr: ARRAY [0..1] OF SndDoubleBufferPtr;
  397.     dbhDoubleBack: ProcPtr;
  398.     END;
  399.  
  400. SndDoubleBufferHeader2Ptr = ^SndDoubleBufferHeader2;
  401. SndDoubleBufferHeader2 = PACKED RECORD
  402.     dbhNumChannels: INTEGER;
  403.     dbhSampleSize: INTEGER;
  404.     dbhCompressionID: INTEGER;
  405.     dbhPacketSize: INTEGER;
  406.     dbhSampleRate: Fixed;
  407.     dbhBufferPtr: ARRAY [0..1] OF SndDoubleBufferPtr;
  408.     dbhDoubleBack: ProcPtr;
  409.     dbhFormat: OSType;
  410.     END;
  411.  
  412.  
  413. FUNCTION SndDoCommand(chan: SndChannelPtr;cmd: SndCommand;noWait: BOOLEAN): OSErr;
  414.     INLINE $A803;
  415. FUNCTION SndDoImmediate(chan: SndChannelPtr;cmd: SndCommand): OSErr;
  416.     INLINE $A804;
  417. FUNCTION SndNewChannel(VAR chan: SndChannelPtr;synth: INTEGER;init: LONGINT;
  418.     userRoutine: ProcPtr): OSErr;
  419.     INLINE $A807;
  420. FUNCTION SndDisposeChannel(chan: SndChannelPtr;quietNow: BOOLEAN): OSErr;
  421.     INLINE $A801;
  422. FUNCTION SndPlay(chan: SndChannelPtr;sndHdl: Handle;async: BOOLEAN): OSErr;
  423.     INLINE $A805;
  424. FUNCTION SndAddModifier(chan: SndChannelPtr;modifier: ProcPtr;id: INTEGER;
  425.     init: LONGINT): OSErr;
  426.     INLINE $A802;
  427. FUNCTION SndControl(id: INTEGER;VAR cmd: SndCommand): OSErr;
  428.     INLINE $A806;
  429.  
  430. PROCEDURE SetSoundVol(level: INTEGER);
  431. PROCEDURE GetSoundVol(VAR level: INTEGER);
  432. PROCEDURE StartSound(synthRec: Ptr;numBytes: LONGINT;completionRtn: ProcPtr);
  433. PROCEDURE StopSound;
  434. FUNCTION SoundDone: BOOLEAN;
  435.  
  436. FUNCTION SndSoundManagerVersion: NumVersion;
  437.     INLINE $203C,$000C,$0008,$A800;
  438. FUNCTION SndStartFilePlay(chan: SndChannelPtr;fRefNum: INTEGER;resNum: INTEGER;
  439.     bufferSize: LONGINT;theBuffer: Ptr;theSelection: AudioSelectionPtr;theCompletion: ProcPtr;
  440.     async: BOOLEAN): OSErr;
  441.     INLINE $203C,$0D00,$0008,$A800;
  442. FUNCTION SndPauseFilePlay(chan: SndChannelPtr): OSErr;
  443.     INLINE $203C,$0204,$0008,$A800;
  444. FUNCTION SndStopFilePlay(chan: SndChannelPtr;quietNow: BOOLEAN): OSErr;
  445.     INLINE $203C,$0308,$0008,$A800;
  446. FUNCTION SndChannelStatus(chan: SndChannelPtr;theLength: INTEGER;theStatus: SCStatusPtr): OSErr;
  447.     INLINE $203C,$0010,$0008,$A800;
  448. FUNCTION SndManagerStatus(theLength: INTEGER;theStatus: SMStatusPtr): OSErr;
  449.     INLINE $203C,$0014,$0008,$A800;
  450. PROCEDURE SndGetSysBeepState(VAR sysBeepState: INTEGER);
  451.     INLINE $203C,$0018,$0008,$A800;
  452. FUNCTION SndSetSysBeepState(sysBeepState: INTEGER): OSErr;
  453.     INLINE $203C,$001C,$0008,$A800;
  454. FUNCTION SndPlayDoubleBuffer(chan: SndChannelPtr;theParams: SndDoubleBufferHeaderPtr): OSErr;
  455.     INLINE $203C,$0020,$0008,$A800;
  456.  
  457. FUNCTION MACEVersion: NumVersion;
  458.     INLINE $203C,$0000,$0010,$A800;
  459. PROCEDURE Comp3to1(inBuffer: Ptr;outBuffer: Ptr;cnt: LONGINT;inState: Ptr;
  460.     outState: Ptr;numChannels: LONGINT;whichChannel: LONGINT);
  461.     INLINE $203C,$0004,$0010,$A800;
  462. PROCEDURE Exp1to3(inBuffer: Ptr;outBuffer: Ptr;cnt: LONGINT;inState: Ptr;
  463.     outState: Ptr;numChannels: LONGINT;whichChannel: LONGINT);
  464.     INLINE $203C,$0008,$0010,$A800;
  465. PROCEDURE Comp6to1(inBuffer: Ptr;outBuffer: Ptr;cnt: LONGINT;inState: Ptr;
  466.     outState: Ptr;numChannels: LONGINT;whichChannel: LONGINT);
  467.     INLINE $203C,$000C,$0010,$A800;
  468. PROCEDURE Exp1to6(inBuffer: Ptr;outBuffer: Ptr;cnt: LONGINT;inState: Ptr;
  469.     outState: Ptr;numChannels: LONGINT;whichChannel: LONGINT);
  470.     INLINE $203C,$0010,$0010,$A800;
  471.  
  472. {Sound Manager 3.0 and later calls}
  473. FUNCTION GetSysBeepVolume(VAR offset: LONGINT): OSErr;
  474.     INLINE $203C,$0224,$0018,$A800;
  475. FUNCTION SetSysBeepVolume(offset: LONGINT): OSErr;
  476.     INLINE $203C,$0228,$0018,$A800;
  477. FUNCTION GetDefaultOutputVolume(VAR offset: LONGINT): OSErr;
  478.     INLINE $203C,$022C,$0018,$A800;
  479. FUNCTION SetDefaultOutputVolume(offset: LONGINT): OSErr;
  480.     INLINE $203C,$0230,$0018,$A800;
  481. FUNCTION GetSoundHeaderOffset(sndHandle: Handle; VAR offset: LONGINT): OSErr;
  482.     INLINE $203C,$0404,$0018,$A800;
  483.  
  484. {$ENDC}    {UsingSound}
  485.  
  486. {$IFC NOT UsingIncludes}
  487.     END.
  488. {$ENDC}
  489.  
  490.